import { Map } from 'immutable'

const user = (state = Map({
    isLogin: localStorage.getItem('isLogin') === 'true',
    token: localStorage.getItem('token') || '',
    adminname: localStorage.getItem('adminname') || '',
    role: localStorage.getItem('role') * 1 || 1
}), action) => {
    switch (action.type) {
        case 'CHANGE_LOGIN_STATE':
            return state.set('isLogin', action.payload)
        case 'CHANGE_TOKEN':
            return state.set('token', action.payload)
        case 'CHANGE_ADMIN_NAME':
            return state.set('adminname', action.payload)
        case 'CHANGE_ROLE':
            return state.set('role', action.payload)
        default:
            return state
    }
}
export default user